#pragma once
#include "SpansLayer.h"
#include <TrueText/Types.h>

namespace TrueText {

inline Rectangle GetLayerBounds(SpansLayer* layer)
{
	Spans& spans = layer->GetSpans();
	if (spans.empty())
		return Rectangle(0, 0, 0, 0);

	int minX = std::numeric_limits<int>::max();
	int maxX = std::numeric_limits<int>::min();
	int minY = std::numeric_limits<int>::max();
	int maxY = std::numeric_limits<int>::min();

	for (Spans::const_iterator span = spans.begin(); span != spans.end(); ++span)
	{
		minX = std::min(minX, span->x);
		maxX = std::max(maxX, span->x + span->width - 1);
		minY = std::min(minY, span->y);
		maxY = std::max(maxY, span->y);
	}

	return Rectangle(minX, minY, maxX, maxY);
}

} // namespace TrueText